package org.springframework.boot.dcj.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.dcj.config.UserConfig;
import org.springframework.boot.dcj.feign.OrderClient;
import org.springframework.boot.dcj.service.CommonService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
// localhost:10000/user/attribute/name
@RequestMapping("/user/attribute")
@Slf4j
public class AttributeController {

    @GetMapping("/name")
    // @SentinelResource 注解用来标识资源是否被限流、降级
    @SentinelResource(value = "name", blockHandler = "blockHandler", fallback = "fallback")
    public String getName() {
        return "dcj";
    }
    // 限流与阻塞处理
    public String blockHandler(BlockException ex) {
        return "限流了";
    }
    // 熔断处理
    public String fallback() {
        return "熔断了";
    }

    @GetMapping("/age")
    public Integer getAge() {
        return 25;
    }
}
